// part1:C09:ex9.27.cpp
// find and delete odd number.
#include <iostream>
#include <forward_list>

int main(void) {
  using namespace std;
  forward_list<int> iflist = {1, 2, 3, 4, 5, 6, 7, 8}; 
  auto prev = iflist.before_begin();
  auto curr = iflist.begin();

  while (curr != iflist.end()) {
    if (*curr & 1) {
      curr = iflist.erase_after(prev); 
    } else {
      prev = curr;
    }
  }

  for (curr = iflist.begin(); curr != iflist.end(); curr++) {
    cout << *curr << " ";  
  }
  cout << endl;

  return 0;
}
